package com.yao.spider.proxy.util;

import com.yao.spider.proxy.entity.Proxy;

/**
 * Created by 单耀 on 2017/12/24.
 */
public class ProxyUtil {
    /**
     * 是否丢弃代理
     * 失败次数大于3，且失败率超过60%，丢弃
     * @param proxy
     * @return
     */
    public static boolean isDiscardProxy(Proxy proxy) {

        int succTimes = proxy.getSuccessfulTimes();
        int failTimes = proxy.getFailureTimes();
        if (failTimes >= 3) {
            double failRate = (failTimes +0.0) / (succTimes + failTimes);
            if (failRate > 0.6) {
                return true;
            }
        }
        return false;
    }
}
